'use strict';

const BaseClient = require('baidu-aip-sdk/src/client/baseClient');

const RequestInfo = require('baidu-aip-sdk/src/client/requestInfo');

const HttpClient = require('baidu-aip-sdk/src/http/httpClientExt');

const objectTools = require('baidu-aip-sdk/src/util/objectTools');

const METHOD_POST = 'POST';

const ENTITYANNOTATION_PATH = '/rpc/2.0/kg/v1/cognitive/entity_annotation';

/**
 * 知识图谱类
 *
 * @class
 * @extends BaseClient
 * @constructor
 * @param {string} appid appid.
 * @param {string} ak  access key.
 * @param {string} sk  security key.
 */
class AipZs extends BaseClient {
    constructor(appId, ak, sk) {
        super(appId, ak, sk);
    }
    commonImpl(param) {
        let httpClient = new HttpClient();
        let apiUrl = param.targetPath;
        delete param.targetPath;
        let requestInfo = new RequestInfo(apiUrl,
            param, METHOD_POST);
        return this.doRequest(requestInfo, httpClient);
    }

    /**
     * 实体标注接口
     *
     * @param {string} text - 待分析文本（目前仅支持GBK编码），长度不超过65536字节
     * @param {Object} options - 可选参数对象，key: value都为string类型
     * @description options - options列表:
     * @return {Promise} - 标准Promise对象
     */
    entityAnnotation(text, options) {
        let param = {
            data: text,
            targetPath: ENTITYANNOTATION_PATH
        };
        return this.commonImpl(objectTools.merge(param, options));
    }
}

module.exports = AipZs;

